package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.ZxTzqk;
import cn.stylefeng.guns.sys.modular.system.model.params.ZxTzqkParam;
import cn.stylefeng.guns.sys.modular.system.model.result.ZxTzqkViewResult;
import cn.stylefeng.guns.sys.modular.system.service.ZxTzqkService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ErrorResponseData;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


/**
 * 控制器
 *
 * @author jiangge
 * @Date 2020-11-20 14:34:42
 */
@Controller
@RequestMapping("/zxTzqk")
public class ZxTzqkController extends BaseController {

    private String PREFIX = "/modular/system/zxTzqk";

    @Autowired
    private ZxTzqkService zxTzqkService;


    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/zxTzqk.html";
    }

    /**
     * 新增页面
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/zxTzqk_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/zxTzqk_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ZxTzqkParam zxTzqkParam) {
        this.zxTzqkService.add(zxTzqkParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ZxTzqkParam zxTzqkParam) {
        this.zxTzqkService.update(zxTzqkParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/editTzqk")
    @ResponseBody
    public ResponseData editTzqk(ZxTzqkParam zxTzqkParam) {
        this.zxTzqkService.editTzqk(zxTzqkParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ZxTzqkParam zxTzqkParam) {
        this.zxTzqkService.delete(zxTzqkParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ZxTzqkParam zxTzqkParam) {
        ZxTzqk detail = this.zxTzqkService.getById(zxTzqkParam.getBtyZxTzqkId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2020-11-20
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ZxTzqkParam zxTzqkParam) {
        return this.zxTzqkService.findPageBySpec(zxTzqkParam);
    }

    /**
     * 投资情况导入
     * 导入excel
     */
    @RequestMapping("/import")
    @ResponseBody
    public ResponseData ddpx(@RequestParam("file") MultipartFile file) throws Exception {

        try {
            String fileName = file.getOriginalFilename();
            ResponseData result = this.zxTzqkService.batchImport(fileName, file);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("解析文件出错");
        }
    }

    /**
     * 投资情况导入
     * 导入excel
     */
    @RequestMapping("/import_md_tzqk")
    @ResponseBody
    public ResponseData ddpx_md_tzqk(@RequestParam("file") MultipartFile file) throws Exception {

        try {
            String fileName = file.getOriginalFilename();
            ResponseData result = this.zxTzqkService.batchImport_md_tzqk(fileName, file);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("解析文件出错");
        }
    }

    /**
     * 投资情况-获取功能
     * @param param
     * @return
     */
    @RequestMapping("/obtainFromBaoxiaodan")
    @ResponseBody
    public ResponseData obtainFromBaoxiaodan(ZxTzqkViewResult param) {

        return this.zxTzqkService.obtainFromBaoxiaodan(param);
    }

    @RequestMapping("/obtainAllFromBaoxiaodan")
    @ResponseBody
    public ResponseData obtainAllFromBaoxiaodan(ZxTzqkViewResult param) {

        return this.zxTzqkService.obtainAllFromBaoxiaodan(param);
    }

    /**
     * 投资情况-一键批量获取
     * @param param
     * @return
     */
    @RequestMapping("/onClickobtainAll")
    @ResponseBody
    public ResponseData onClickobtainAll(ZxTzqkViewResult param) {
        return this.zxTzqkService.onClickobtainAll(param);
    }
    /**
     * 投资情况导入
     * 导入excel
     */
    @RequestMapping("/btnImportMdTzCb")
    @ResponseBody
    public ResponseData btnImportMdTzCb(@RequestParam("file") MultipartFile file) throws Exception {
        try {
            ResponseData result = this.zxTzqkService.importMdTzCb(file);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("解析文件出错");
        }
    }

    /**
     * 批量投资、门店、预算导入
     * 导入excel
     */
    @RequestMapping("/batchImportMdTzys")
    @ResponseBody
    public ResponseData batchImportMdTzys() throws Exception {
        try {
            ResponseData result = this.zxTzqkService.batchImportMdTzCb();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("解析文件出错");
        }
    }

    /**
     * 对账同步
     * 导入excel
     */
    @RequestMapping("/duizhangTongbu")
    @ResponseBody
    public ResponseData duizhangTongbu() throws Exception {
        ResponseData result = this.zxTzqkService.duizhangTongbu();
        return result;
    }
}


